package com.ilink.teacherservice.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ilink.ilinkcommon.domain.PO.studyservice.CourseSource;
import com.ilink.ilinkcommon.domain.PO.studyservice.FileTranscriptionTaskResponse;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <h3>new-ilink-java-backend</h3>
 *
 * @Description <p>用于实现MYSQL音视频数据的操作</p>
 * @Author pengshiyao
 * @Date 2024-09-16 15:21
 **/
@Mapper
public interface CourseSourceMapper extends BaseMapper<CourseSource> {

    @Delete("DELETE cs, ftti FROM coursesource cs " +
        "INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id " +
        "WHERE cs.course_id = #{courseId}")
    void deleteCourseResourcesByCourseId(@Param("courseId") Long courseId);

    @Delete("DELETE cs, ftti FROM coursesource cs " +
        "INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id " +
        "WHERE cs.coursesource_id = #{sourceId}")
    int deleteCourseResourcesBySourCeId(@Param("sourceId") Long sourceId);

    @Delete("DELETE cs, ftti FROM coursesource cs " +
        "INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id " +
        "WHERE cs.file_id = #{courseFileId}")
    int deleteCourseResourcesBycourseFileId(@Param("courseFileId")Long courseFileId);
    @Delete("DELETE FROM coursesource cs " +
        "WHERE cs.coursesource_id = #{courseFileId}")
    int deleteCourseResourcesBycourseSourceIdNoTask(@Param("courseFileId")Long courseFileId);
    @Delete("DELETE FROM coursesource cs " +
        "WHERE cs.file_id = #{courseFileId}")
    int deleteCourseResourcesBycourseFileIdNoTask(@Param("courseFileId")Long courseFileId);

    @Select("SELECT ftti.* FROM coursesource cs " +
        "INNER JOIN file_transcription_task_info ftti ON cs.task_id = ftti.task_id " +
        "WHERE cs.coursesource_id = #{sourceId}")
    FileTranscriptionTaskResponse selectTransResultById(Long courseSourceId);
}

